package com.onepice.mlp.core.serviceImpl;

import com.onepice.mlp.core.service.MenuService;
import com.onepice.mlp.data.dao.MenuDao;
import com.onepice.mlp.data.entity.Menu;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

/**
 * @author FireWang
 * @date 2022/07/11 23:25:03
 */
@Service
@AllArgsConstructor
@Transactional
public class MenuServiceImpl implements MenuService {
    private MenuDao menuDao;

    @Override
    public List<Menu> getAll() {
        return menuDao.findByStatus(1);
    }

    @Override
    public Menu getById(Integer id) {
        Optional<Menu> menu = menuDao.findById(id);
        return menu.get();
    }

    @Override
    public void insert(Menu menu) {
        menuDao.save(menu);
    }

    @Override
    public void update(Menu menu) {
        menuDao.save(menu);
    }

    @Override
    public void deleteById(Integer id) {
        menuDao.deleteById(id);
    }
}
